xxx: Add a hack to make paintables transform to/from objects
authorBenjamin Otte <otte@redhat.com>
Tue, 26 Nov 2019 05:09:20 +0000 (06:09 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 May 2020 23:26:46 +0000 (19:26 -0400)
See also: https://gitlab.gnome.org/GNOME/glib/merge_requests/1251

gdk/gdkpaintable.c

index fc91762784a5bf4bb94465d7247339211600a8e2..56b13bcd95fa7cb27a68e43059897c75363b81d4 100644 (file)
@@ -136,6 +136,16 @@ static double gdk_paintable_default_get_intrinsic_aspect_ratio (GdkPaintable *pa
   return (double) width / height;
 };
 
+static void
+g_value_object_transform_value (const GValue *src_value,
+                               GValue       *dest_value)
+{
+  if (src_value->data[0].v_pointer && g_type_is_a (G_OBJECT_TYPE (src_value->data[0].v_pointer), G_VALUE_TYPE (dest_value)))
+    dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
+  else
+    dest_value->data[0].v_pointer = NULL;
+}
+
 static void
 gdk_paintable_default_init (GdkPaintableInterface *iface)
 {
@@ -146,6 +156,9 @@ gdk_paintable_default_init (GdkPaintableInterface *iface)
   iface->get_intrinsic_height = gdk_paintable_default_get_intrinsic_height;
   iface->get_intrinsic_aspect_ratio = gdk_paintable_default_get_intrinsic_aspect_ratio;
 
+  g_value_register_transform_func (G_TYPE_OBJECT, GDK_TYPE_PAINTABLE, g_value_object_transform_value);
+  g_value_register_transform_func (GDK_TYPE_PAINTABLE, G_TYPE_OBJECT, g_value_object_transform_value);
+
   /**
    * GdkPaintable::invalidate-contents
    * @paintable: a #GdkPaintable